﻿import com.dmotiko.bolacua.*
import com.dmotiko.general.*
import com.dmotiko.util.*
import mx.utils.Delegate
import mx.transitions.*
import mx.transitions.easing.*

class CanvasBolacua
extends BaseClip {
	
	private var mcMiddle:MovieClip;
	private var mcBottom:MovieClip;
	private var mcMask:MovieClip;
	private var middleScale:Tween;
	private var oListener:Object;
			
	private function CanvasBolacua() {
		
		mcMiddle.setMask(mcMask);
		var root:CanvasBolacua = this;
		oListener = new Object();
		oListener.onMotionFinished = function() {
			root.interpolationEnd();
		}
	}
	
	public function loadingSection() {
		if (middleScale) middleScale.stop();
		var nHeight:Number = 550;
		var root:CanvasBolacua = this;
		/*
		middleScale =  new Tween( mcMiddle, "_height", Regular.easeOut, mcMiddle._height, nHeight, 0.5, true );
		middleScale.addListener( oListener );
		nHeight += mcBottom._height;
		mcMask.onEnterFrame = function() {
			this.mcMiddle._height = root.mcMiddle._height - this.mcBottom._height + 2;
			this.mcBottom._y = this.mcMiddle._y + this.mcMiddle._height - 2;
		}
		*/
		mcMiddle._height = nHeight;
		mcMask.mcMiddle._height = mcMiddle._height - mcMask.mcBottom._height + 2 ;
		mcMask.mcBottom._y = mcMask.mcMiddle._y - mcMask.mcMiddle._height - 2;
	}
	
	public function sectionChanged() {
		
		if(middleScale) middleScale.stop();
		
		var nHeight:Number;
		switch(BolacuaSite.getApp().getSection()) {
			case BolacuaSite.HOME:
			nHeight = 658;
			break;
			
			case BolacuaSite.ALOJAMIENTO:
			nHeight = 2500;
			break;
			
			case BolacuaSite.RESTAURANT:
			nHeight = 1300;
			break;
			
			case BolacuaSite.INFRAESTRUCTURA:
			nHeight = 1000;
			break;
			
			case BolacuaSite.COMO_LLEGAR:
			nHeight = 1315;
			break;
			
			case BolacuaSite.TARIFAS:
			nHeight = 1641;
			break;
						
			case BolacuaSite.EVENTOS:
			nHeight = 1820;
			break;
			
			case BolacuaSite.CONTACTO:
			nHeight = 550;
			break;
		}
		setCanvasHeight(nHeight);		
	}
	
	public function setCanvasHeight(nHeight):Void {
		var root = this;
		BolacuaSite.getApp().setWindowSize(nHeight, 0);
		/*
		if ( middleScale ) middleScale.stop();
		middleScale =  new Tween( mcMiddle, "_height", Regular.easeOut, mcMiddle._height, nHeight, 0.5, true );
		middleScale.addListener( oListener );
		nHeight += mcBottom._height;
		mcMask.onEnterFrame = function() {
			this.mcMiddle._height = root.mcMiddle._height - this.mcBottom._height + 2;
			this.mcBottom._y = this.mcMiddle._y + this.mcMiddle._height - 2;
		}
		*/
		mcMiddle._height = nHeight;
		mcMask.mcMiddle._height = mcMiddle._height - mcMask.mcBottom._height + 2;
		mcMask.mcBottom._y = mcMask.mcMiddle._y - mcMask.mcMiddle._height - 2;
	}
	
	private function interpolationEnd() {
		mcMask.mcMiddle._height = this.mcMiddle._height - mcMask.mcBottom._height + 2;
		mcMask.mcBottom._y = mcMask.mcMiddle._y + mcMask.mcMiddle._height - 2;
		delete mcMask.onEnterFrame;
	}
	
}